/*
 * This file is part of Cadmium.
 * Copyright (C) 2007-2010 Xavier Clerc.
 *
 * Cadmium is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Cadmium is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package fr.x9c.cadmium.kernel;

import java.io.InputStream;
import java.net.URL;

/**
 * This class implements a basic file hook that is used when embedded mode is
 * activated.
 *
 * @author <a href="mailto:cadmium@x9c.fr">Xavier Clerc</a>
 * @version 1.0
 * @since 1.0
 */
public final class BasicFileHook implements FileHook {

    /** Class to be used as base for resource loading. */
    private final Class base;

    /**
     * Constructs a file hook with given base.
     * @param base class to be used as base for resource loading
     *             (if <tt>null</tt> this class with be used as base)
     */
    public BasicFileHook(final Class base) {
        this.base = base;
    } // end constructor(Class)

    /**
     * {@inheritDoc}
     */
    @Override
    public InputStream getInputStream(final String file) {
        return (this.base != null ? this.base : BasicFileHook.class).getResourceAsStream(file);
    } // end method 'getInputStream(String)'

    /**
     * {@inheritDoc}
     */
    @Override
    public URL getURL(final String file) {
        return (this.base != null ? this.base : BasicFileHook.class).getResource(file);
    } // end method 'getURL(String)'

} // end class 'BasicFileHook'
